//保存用户
export function save() {
  return {
    url: '/user/save',
    type: 'post',
    data: {
      code: 200,
      message: '成功',
      data: 1
    }
  }
}

//删除用户
export function bactchDelete() {
  return {
    url: '/user/delete',
    type: 'post',
    data: {
      code: 200,
      message: '成功',
      data: 1
    }
  }
}

//分页查询
export function findPage(params) {
  let findPageData = {'code': 200, 'message': '成功', 'data': {}};
  let pageNum = 1;
  let pageSize = 10;
  let content = this.getContent(pageNum, pageSize);
  findPageData.data.pageNum = pageNum;
  findPageData.data.pageSize = pageSize;
  findPageData.data.totalSize = 50;
  findPageData.data.content = content;
  return {
    url: '/user/findPage',
    type: 'post',
    data: findPageData
  }
}

export function getContent(pageNum, pageSize) {
  let content = {};
  for (let i = 0; i < pageSize; i++) {
    let obj = {};
    let index = ((pageNum - 1) * pageSize) + i + 1;
    obj.id = index;
    obj.name = 'ShangYueShang' + index;
    obj.password = '123@qwe';
    obj.salt = '123456';
    obj.email = 'sys' + index + '@qq.com';
    obj.mobile = '2423432432';
    obj.status = 1;
    obj.deptId = 12;
    obj.deptName = '技术部';
    if (i % 2 === 0) {
      obj.deptId = 13;
      obj.deptName = '市场部';
    }
    obj.creator = 'admin';
    obj.createTime = '2022-01-08 17:46:46.222';
    content.push(obj);
  }
  return content;
}

//根据名称查询
export const findByName = (param) => {
  return axios({
    url: '/user/findByName',
    method: 'get',
    param
  })
};

//查询用户权限
export function findPermissions() {
  let permsData = {
    'code': 200, 'message': '成功', 'data': [
      'sys:user:view',
      'sys:user:delete',
      'sys:user:findPage',
      'sys:user:save',
      'sys:user:edit',
    ]
  };
  return {
    url: '/user/findPermissions',
    type: 'get',
    data: permsData
  }
}

